package com.srd.phone.bean;

import com.srd.phone.utils.CommonUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;

public class MessageBean {

    public int id;
    public int state;
    public String content;
    public String ctime;
    public String title;
    public boolean isSelected = false;

    public static List<MessageBean> parseData(String json){
        List<MessageBean> list = new ArrayList<MessageBean>();
        try {
            JSONArray jsonArray = new JSONArray(json);
            for (int i = 0; i < jsonArray.length(); i++) {
                MessageBean item = new MessageBean();
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                item.id = jsonObject.optInt("id");
                item.state = jsonObject.optInt("state");
                item.ctime = CommonUtils.formatDataStr(jsonObject.optString("ctime"));
                item.content = jsonObject.optString("content");
                item.title = jsonObject.optString("title");
                list.add(item);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return list;
    }
}

